package com.jjy.dao.impl;

import com.jjy.dao.GoodsDao;
import com.jjy.pojo.Goods;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Repository;

import java.util.List;


public class GoodsDaoImpl implements GoodsDao{
  private SqlSessionFactory sqlSessionFactory;
  public GoodsDaoImpl(SqlSessionFactory sqlSessionFactory) {
    this.sqlSessionFactory = sqlSessionFactory;
  }

  @Override
  public Goods getGoodsById(Long id) {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    return null;
  }

  @Override
  public Goods getGoodsByNo(Long number) {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    return sqlSession.selectOne("getGoodsByNo" , number);
  }

  @Override
  public List<Goods> getAllGoods() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    return sqlSession.selectList("getAllGoods");
  }

  @Override
  public List<Goods> getGoodsByParams(Goods goods) {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    return sqlSession.selectList("getGoodsByParams" , goods);
  }

  @Override
  public int createGoods(Goods goods) {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    return sqlSession.insert("createGoods" , goods);
  }

  @Override
  public int updateGoods(Goods goods) {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    return sqlSession.insert("updateGoods" , goods);
  }

}
